package com.xbongbong.saas.model.impl;

import com.xbongbong.paas.toolbox.util.DateUtil;
import com.xbongbong.saas.domain.dao.PublicGroupCustomerDao;
import com.xbongbong.saas.domain.entity.PublicGroupCustomerEntity;
import com.xbongbong.saas.model.PublicGroupCustomerModel;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * @description: 公海池客户
 * @Author: hongxiao
 * @date: 2019-03-05 22:36
 * @since v1.0
 */
@Service("publicGroupCustomerModel")
public class PublicGroupCustomerModelImpl implements PublicGroupCustomerModel {
    @Resource
    private PublicGroupCustomerDao publicGroupCustomerDao;

    @Override
    public Integer insert(PublicGroupCustomerEntity entity){
        long now =DateUtil.getInt();
        entity.setAddTime(now);
        entity.setUpdateTime(now);

        return publicGroupCustomerDao.insert(entity);
    }

    @Override
    public Integer update(PublicGroupCustomerEntity entity){
        entity.setUpdateTime((long)DateUtil.getInt());

        return publicGroupCustomerDao.update(entity);
    }

    @Override
    public Integer save(PublicGroupCustomerEntity entity){

        if(entity.getId() == null || Objects.equals(0L, entity.getId())) {
            return publicGroupCustomerDao.insert(entity);
        }
        return publicGroupCustomerDao.update(entity);
    }

    @Override
    public Integer insertBatch(List<PublicGroupCustomerEntity> list) {
        return publicGroupCustomerDao.insertBatch(list);
    }

    @Override
    public Integer deleteByKey( Long key,String corpid){
        return publicGroupCustomerDao.deleteByKey(key,corpid);
    }

    @Override
    public PublicGroupCustomerEntity getByKey( Long key,String corpid){
        return publicGroupCustomerDao.getByKey(key,corpid);
    }

    @Override
    public List<PublicGroupCustomerEntity> findEntitys(Map<String ,Object> param){
        return publicGroupCustomerDao.findEntitys(param);
    }

    @Override
    public Integer getEntitysCount(Map<String ,Object>  param){
        return publicGroupCustomerDao.getEntitysCount(param);
    }

    @Override
    public List findEntitysWithoutSub(Map<String, Object> param) {
        return null;
    }

    @Override
    public Integer deleteByPublicGroupId(Long publicGroupId,String corpid){
        return publicGroupCustomerDao.deleteByPublicGroupId(publicGroupId, corpid);
    }

    /**
     * 删除某些分组所有的（或与某客户的）关联关系
     * @param publicGroupIdIn
     * @param corpid
     * @param customerId
     * @return
     * @author zheng.li
     * @time 2017-7-3 下午1:34:13
     */
    @Override
    public Integer deleteByPublicGroupIdList(List<Long> publicGroupIdIn,String corpid,Long customerId){
        return publicGroupCustomerDao.deleteByPublicGroupIdList(publicGroupIdIn, corpid,customerId);
    }

    @Override
    public Integer deleteByCustomerId(Long customerId,String corpid){
        return publicGroupCustomerDao.deleteByCustomerId(customerId, corpid);
    }

    /**
     * 删除某些客户所有的（或与某分组的）关联关系
     * @param customerIdIn
     * @param corpid
     * @param publicGroupId
     * @return
     * @author zheng.li
     * @time 2017-7-3 下午1:34:33
     */
    @Override
    public Integer deleteByCustomerIdList(List<Long> customerIdIn,String corpid,Long publicGroupId){
        return publicGroupCustomerDao.deleteByCustomerIdList(customerIdIn, corpid,publicGroupId);
    }

    @Override
    public List<Long> findCustomerIds(Map<String ,Object>  param){
        return publicGroupCustomerDao.findCustomerIds(param);
    }

    /**
     * 获取公海分组已关联客户数的对应关系
     * @param param
     * @return
     * @since 3.8
     * @version 3.8
     * @author zheng.li
     * @time 2017-7-10 下午8:19:31
     */
    @Override
    public List<Map<String,Object>> getBindCountMap(Map<String,Object> param){
        return publicGroupCustomerDao.getBindCountMap(param);
    }
}
